package Java8.function;

import java.util.function.Function;
import java.util.function.IntBinaryOperator;

public class TestFunction {

  public static void main(String[] args) {

      TestFunction test = new TestFunction();

      System.out.println(test.compute(5, value -> value * value)); //25 计算平方
      System.out.println(test.compute(5, value -> value + value)); //10 求和
      System.out.println(test.compute(5, value -> value - 2)); //3

      System.out.println(test.compute2(1, 2, (a, b) -> a + b));
  }


    public int compute2(int a, int b, IntBinaryOperator intBinaryOperator) {
        return intBinaryOperator.applyAsInt(a, b);
    }

    public int compute(int a, Function<Integer, Integer> function) {
        int result = function.apply(a);
        return result;
    }
}
